﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcs.Web.Admin.distribution
{
    public partial class confirmnum : Web.Admin.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["dnmu"] != null && Request.Params["dnmu"].Trim() != "")
                {
                    txtnum.Text = Request.Params["dnmu"].ToString();
                    hfnums.Value = txtnum.Text;
                }
                if (Request.Params["type"] != null && Request.Params["type"].Trim() != "")
                {
                    if (Request.Params["type"] == "1")
                    {
                        lblmsg.Text = "已到货数量";
                    }
                    else
                    {
                        pcheck.Visible = true;
                        btnNOOK.Visible = true;
                        lblmsg.Text = "初验数量";
                    }
                }
                Page.DataBind();
            }

        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (Request.Params["type"] != null && Request.Params["type"].Trim() != "")
                {
                    if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                    {
                        int id = (Convert.ToInt32(Request.Params["id"]));
                        lcs.BLL.distribution bll = new lcs.BLL.distribution();
                        decimal num = 0;
                        if (txtnum.Text.Trim() != "")
                            num = decimal.Parse(txtnum.Text);
                        if (Request.Params["type"] == "1")
                        {
                            if (txtnum.Text != hfnums.Value)
                            {
                                lcs.BLL.distribution bd = new BLL.distribution();
                                DataSet ds = bd.GetListv(" and did=" + id);
                                if (ds.Tables[0].Rows.Count == 1)
                                {
                                    lcs.Model.badness model = new lcs.Model.badness();
                                    model.bdesp = "到货数量不对,应为" + hfnums.Value + "，实到" + txtnum.Text + "。";
                                    model.bdate = DateTime.Now;
                                    model.bspot = ds.Tables[0].Rows[0]["winBid"].ToString();
                                    model.project = ds.Tables[0].Rows[0]["projectName"].ToString();
                                    model.material = ds.Tables[0].Rows[0]["material"].ToString();
                                    model.sid = int.Parse(ds.Tables[0].Rows[0]["sid"].ToString());
                                    lcs.BLL.badness bllb = new lcs.BLL.badness();
                                    bllb.Add(model);
                                }
                            }
                            bll.Updateaognum(id, num);
                            //更改最后一次日期
                            Maticsoft.BLL.monthSupplayPlan mb = new Maticsoft.BLL.monthSupplayPlan();
                            mb.Updatedate(0, id);
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "alert('成功！');closedialog();", true);

                        }
                        else
                        {
                            lcs.BLL.distribution bd = new BLL.distribution();
                            DataSet ds = bd.GetListv(" and did=" + id);
                            if (ds.Tables[0].Rows.Count == 1)
                            {
                                if (txtnum.Text != hfnums.Value)
                                {

                                    lcs.Model.badness model = new lcs.Model.badness();
                                    model.bdesp = "初验数量不对,应为" + hfnums.Value + "，实到" + txtnum.Text + "。";
                                    model.bdate = DateTime.Now;
                                    model.bspot = ds.Tables[0].Rows[0]["winBid"].ToString();
                                    model.project = ds.Tables[0].Rows[0]["projectName"].ToString();
                                    model.material = ds.Tables[0].Rows[0]["material"].ToString();
                                    model.sid = int.Parse(ds.Tables[0].Rows[0]["sid"].ToString());

                                    lcs.BLL.badness bllb = new lcs.BLL.badness();
                                    bllb.Add(model);

                                }
                                string desp = "";
                                if (ckbwg.Checked == false)
                                {
                                    desp += "外观不完好。";                                    
                                }
                                if (ckblld.Checked == false)
                                {
                                    desp += "联络单不完整。";
                                    
                                }
                                if (ckbzl.Checked == false)
                                {
                                    desp += "资料不齐全。";                                    
                                }
                                if (ckbxh.Checked == false)
                                {
                                   desp += "型号不一致。";                                   
                                }
                                if (desp != "")
                                {
                                    lcs.Model.badness model = new lcs.Model.badness();
                                    model.bdesp = desp;
                                    model.bdate = DateTime.Now;
                                    model.bspot = ds.Tables[0].Rows[0]["winBid"].ToString();
                                    model.project = ds.Tables[0].Rows[0]["projectName"].ToString();
                                    model.material = ds.Tables[0].Rows[0]["material"].ToString();
                                    model.sid = int.Parse(ds.Tables[0].Rows[0]["sid"].ToString());
                                    lcs.BLL.badness bllb = new lcs.BLL.badness();
                                    bllb.Add(model);
                                }
                            }
                            bll.Updatepinum(id, num);
                            Maticsoft.BLL.monthSupplayPlan mb = new Maticsoft.BLL.monthSupplayPlan();
                            mb.Updatedate(1, id);
                            bll.addmaterial(id);
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "alert('成功！');closedialog();", true);

                        }
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "alert('没有可操作数据！');closedialog();", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "alert('没有可操作数据！');closedialog();", true);
                }
            }
        }

        protected void btnNOOK_Click(object sender, EventArgs e)
        {
            if (Request.Params["type"] != null && Request.Params["type"].Trim() != "")
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    if (Request.Params["type"] != "1")
                    {
                        int id = (Convert.ToInt32(Request.Params["id"]));
                        lcs.BLL.distribution bd = new BLL.distribution();
                        DataSet ds = bd.GetListv(" and did=" + id);
                        if (ds.Tables[0].Rows.Count == 1)
                        {
                            string desp = "";
                            if (ckbwg.Checked == false)
                            {
                                desp += "外观不完好。";
                            }
                            if (ckblld.Checked == false)
                            {
                                desp += "联络单不完整。";

                            }
                            if (ckbzl.Checked == false)
                            {
                                desp += "资料不齐全。";
                            }
                            if (ckbxh.Checked == false)
                            {
                                desp += "型号不一致。";
                            }
                            if (desp != "")
                            {
                                lcs.Model.badness model = new lcs.Model.badness();
                                model.bdesp = desp;
                                model.bdate = DateTime.Now;
                                model.bspot = ds.Tables[0].Rows[0]["winBid"].ToString();
                                model.project = ds.Tables[0].Rows[0]["projectName"].ToString();
                                model.material = ds.Tables[0].Rows[0]["material"].ToString();
                                model.sid = int.Parse(ds.Tables[0].Rows[0]["sid"].ToString());
                                lcs.BLL.badness bllb = new lcs.BLL.badness();
                                bllb.Add(model);
                            }
                        }
                    }
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "closedialog();", true);
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "alert('没有可操作数据！');closedialog();", true);
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "alert('没有可操作数据！');closedialog();", true);
            }

        }
    }
}